﻿using System.Configuration;
using System.Web.Mvc;
using Twitterizer;

namespace Socaloud.Controllers {
    public class TwitterController : Controller {

        private readonly OAuthTokens _tokens;
        public TwitterController() {
            _tokens = new OAuthTokens {
                ConsumerKey = ConfigurationManager.AppSettings["customerKey"],
                ConsumerSecret = ConfigurationManager.AppSettings["customerSecret"],
                AccessToken = ConfigurationManager.AppSettings["accessToken"],
                AccessTokenSecret = ConfigurationManager.AppSettings["accessTokenSecret"]
            };
        }

        [HttpPost]
        public JsonResult Retweet(decimal id) {
            var response = TwitterStatus.Retweet(_tokens, id);
            return Json(response);
        }

        [HttpPost]
        public JsonResult Reply(decimal id, string reply) {
            var options = new StatusUpdateOptions {
                InReplyToStatusId = id
            };

            var response = TwitterStatus.Update(_tokens, reply, options);
            return Json(response);
        }

        [HttpPost]
        public JsonResult Favorite(decimal id) {
            var response = TwitterFavorite.Create(_tokens, id);
            return Json(response);
        }

        [HttpPost]
        public JsonResult Delete(decimal id) {
            var response = TwitterStatus.Delete(_tokens, id);
            return Json(response);
        }

    }
}
